package com.ruoyi.event.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.event.domain.bo.EventDzbgBo;
import com.ruoyi.event.domain.vo.EventDzbgVo;
import com.ruoyi.event.service.IEventDzbgService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 地址变更
 *
 * @author strongme
 * @date 2023-02-04
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/event/dzbg")
public class EventDzbgController extends BaseController {

    private final IEventDzbgService iEventDzbgService;

    /**
     * 查询地址变更列表
     */
    @GetMapping("/list")
    public TableDataInfo<EventDzbgVo> list(EventDzbgBo bo, PageQuery pageQuery) {
        return iEventDzbgService.queryPageList(bo, pageQuery);
    }

    @PostMapping("query")
    public R<List<EventDzbgVo>> query(@RequestBody EventDzbgBo bo) {
        return R.ok(iEventDzbgService.queryList(bo));
    }

    /**
     * 导出地址变更列表
     */
    @Log(title = "地址变更", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(EventDzbgBo bo, HttpServletResponse response) {
        List<EventDzbgVo> list = iEventDzbgService.queryList(bo);
        ExcelUtil.exportExcel(list, "地址变更", EventDzbgVo.class, response);
    }

    /**
     * 获取地址变更详细信息
     *
     * @param dzbgId 主键
     */
    @GetMapping("/{dzbgId}")
    public R<EventDzbgVo> getInfo(@NotNull(message = "主键不能为空")
                                  @PathVariable Long dzbgId) {
        return R.ok(iEventDzbgService.queryById(dzbgId));
    }

    /**
     * 新增地址变更
     */
    @Log(title = "地址变更", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody EventDzbgBo bo) {
        return toAjax(iEventDzbgService.insertByBo(bo));
    }

    /**
     * 修改地址变更
     */
    @Log(title = "地址变更", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody EventDzbgBo bo) {
        return toAjax(iEventDzbgService.updateByBo(bo));
    }

    /**
     * 删除地址变更
     *
     * @param dzbgIds 主键串
     */
    @Log(title = "地址变更", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dzbgIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] dzbgIds) {
        return toAjax(iEventDzbgService.deleteWithValidByIds(Arrays.asList(dzbgIds), true));
    }
}
